/*
 * CXSerialPort.h
 *
 *  Created on: May 21, 2014
 *      Author: rayin
 */

#ifndef CXSERIALPORT_H_
#define CXSERIALPORT_H_

#include       <stdlib.h>
#include       <unistd.h>
#include       <sys/types.h>
#include       <sys/stat.h>
#include       <fcntl.h>
#include       <termios.h>
#include       <errno.h>

#include 		<string.h>
#include 		<stdio.h>

#include 		<string>
#include 		<deque>
#include <QByteArray>
using namespace std;

class CXSerialPort {
private:
	int m_fd;
	int m_buad;
	int m_databit;
	int m_stopbit;
	enum _PARTYPE{
		PAR_NONE,
		PAR_ODD,
		PAR_EVEN,
	} m_polarity;
	unsigned char m_tmpbuf[4096];
public:
	CXSerialPort();
	CXSerialPort(string port);
	CXSerialPort(string port,int buad);
	bool setBuad(int buad);
	bool setDataBit(int databit);
	bool setStopBit(int stopbit);
	bool setPolarity(_PARTYPE type);
	bool updateParameter();
    bool pushBuffer(QByteArray &date);
    bool flushBuffer(QByteArray &date);

	virtual ~CXSerialPort();

};

#endif /* CXSERIALPORT_H_ */
